//
//  BookStackCategoryController.m
//  ProjectDemo
//
//  Created by IOS3 on 2018/11/2.
//  Copyright © 2018 IOS3. All rights reserved.
//

#import "BookStackCategoryController.h"
#import "BookStackCategoryLeftTableView.h"
#import "BookStackCategoryRightTableView.h"



@interface BookStackCategoryController ()

@property (nonatomic, strong) BookStackCategoryLeftTableView *leftTableView;
@property (nonatomic, strong) BookStackCategoryRightTableView *rightTableView;

@end

@implementation BookStackCategoryController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initializes];
    
    
    
    
}

- (void)initializes {

    self.leftTableView = [[BookStackCategoryLeftTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.rightTableView = [[BookStackCategoryRightTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.view addSubview:self.leftTableView];
    [self.view addSubview:self.rightTableView];
    
    
    [self.leftTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(TOP_HEIGHT);
        make.left.bottom.mas_equalTo(self.view);
        make.width.mas_equalTo(130);
    }];
    [self.rightTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(TOP_HEIGHT);
        make.right.bottom.mas_equalTo(self.view);
        make.left.mas_equalTo(self.leftTableView.mas_right);
    }];
    
    [self childTableViewCallBack];
}

- (void)childTableViewCallBack {
    __weak typeof(self)weakSelf = self;
    self.leftTableView.selectIndexPathAt = ^(NSIndexPath * _Nonnull indexPath) {
        NSIndexPath *rightIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row];
        [weakSelf.rightTableView scrollToRowAtIndexPath:rightIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    };
    self.rightTableView.selectIndexPathAt = ^(NSIndexPath * _Nonnull indexPath) {
        DLog(@"rightTableView click: (%ld - %ld)", indexPath.section, indexPath.row);
    };
    self.rightTableView.visibleTopSectionAt = ^(NSInteger index) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
        [weakSelf.leftTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    };
}

@end
